#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll T;
ll n,m,L,V;
ll d,v,a;
ll ans,mans;
ll struct Info{
	ll di;
	ll vi;
	ll ai;
	};Info info[1000000];
ll dmax;ll dmin;
ll temp;
int flag=0;
ll mn;
ll mx;
ll arr[100000];
double deltax;
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	cin>>T;
	for(int i=1;i<=T;i++){
		cin>>n>>m>>L>>V;
		for(int j=1;j<=n;j++){
			cin>>info[j].di>>info[j].vi>>info[j].ai;
			if(info[j].ai!=0) flag=1;
			if(info[j].ai<mn) mn=info[j].ai;
			if(info[j].ai>mx) mx=info[j].ai;
			}
		if(flag==1&&mn>0) flag=1;
		else if(flag==1&&mx<0) flag=-1;
		for(int k=1;k<=m;k++){
			cin>>temp;
			arr[k]=temp;
			if(temp>dmax) dmax=temp;
			if(temp<dmin) dmin=temp;
			}
		if(flag==0){
			for(int j=1;j<=n;j++){
				if(info[j].di<=dmax&&info[j].vi>V) ans++;
				}
		}
		if(flag==1){
			for(int j=1;j<=n;j++){
				if(info[j].vi<V){
					deltax=(V*V-(info[j].vi*info[j].vi))/(2*info[j].ai*1.0)*1.0;
					if(deltax+info[j].di<=dmax) ans++;
					}
				if(info[j].vi>=V&&info[j].di<=dmax) ans++;
				}
			}
		if(flag==0) cout<<ans<<' '<<m-1<<endl;
		if(flag==1) cout<<ans<<' '<<m-1<<endl;
		ans=0;
		}
	return 0;
}
